// Problem: C. Сортировка вагонов
// Contest: Codeforces - Codeforces Round 335 (Div. 2)
// URL: https://codeforces.com/contest/606/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define F first
#define S second
#define in insert
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 123;
const int P = 320;
const int inf = 1e9 + 7;
ll n, k;
ll a[N];
ll dp[N];
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0] = 0;
ll mx = 0;
for(int i = 1; i <= n; i++) {
dp[a[i]] = dp[a[i] - 1] + 1;
if(mx < dp[a[i]]) {
mx = dp[a[i]];
}
}
cout << n - mx << '\n';
}
// 28 37 48 49 55 56 57 58 67 9
// 9 + 1 +
int main() {
//freopen("knight.in", "r", stdin);
//freopen("knight.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tt = 1;
//cin >> tt;
while(tt--) {
solve();
}
}
1101A - Minimum Integer | 985D - Sand Fortress |
1279A - New Year Garland | 1279B - Verse For Santa |
202A - LLPS | 978A - Remove Duplicates |
1304A - Two Rabbits | 225A - Dice Tower |
1660D - Maximum Product Strikes Back | 1513A - Array and Peaks |
1251B - Binary Palindromes | 768B - Code For 1 |
363B - Fence | 991B - Getting an A |
246A - Buggy Sorting | 884A - Book Reading |
1180A - Alex and a Rhombus | 445A - DZY Loves Chessboard |
1372A - Omkar and Completion | 159D - Palindrome pairs |
981B - Businessmen Problems | 1668A - Direction Change |
1667B - Optimal Partition | 1668B - Social Distance |
88B - Keyboard | 580B - Kefa and Company |
960A - Check the string | 1220A - Cards |
897A - Scarborough Fair | 1433B - Yet Another Bookshelf |